/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package au.csiro.nt.psdp.dao.impl;

/**
 *
 * @author Administrator
 */
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import java.util.List;
import au.csiro.nt.psdp.model.Ims;
import au.csiro.nt.psdp.dao.ImsDao;
import org.hibernate.FlushMode;
import org.hibernate.Session;
public class ImsDaoImpl extends HibernateDaoSupport implements ImsDao{
    public Ims getaIms(int pIms){
        Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
        session.beginTransaction();

		Ims tradingSession = (Ims) session.get(Ims.class, pIms);
        session.flush();
        session.getTransaction().commit();

		return tradingSession;
    }
    public List<Ims> getIms()
    {
        return getHibernateTemplate().find("from Ims m order by upper(m.username)");
    }
    public List<Ims> getIms(String user)
    {          
        return getHibernateTemplate().find("from Ims m where m.recvmessage is null and m.mobileto = ? " , user);// and m.mobileto = ? " , user
    }
    public int saveIms(Ims aIms)
    {
        Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
        session.beginTransaction();
        session.setFlushMode(FlushMode.AUTO);

        session.saveOrUpdate(aIms);
        session.flush();
        session.getTransaction().commit();


        return aIms.getImsid();
    }
}
